package cn.hiapi.core.basic.service;

import cn.hiapi.core.basic.BasicEntity;
import cn.hiapi.core.basic.query.BasicQuery;
import cn.hiapi.core.basic.query.QueryWrapper;
import cn.hiapi.core.basic.response.ResponseEntity;
import com.alibaba.fastjson2.JSONObject;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author AdinZ
 * @date 2021/1/6 9:40 上午
 */
public interface BasicService<T extends BasicEntity, ID extends Serializable>   {

    EntityManagerFactory getFactory();

    void closeEntityManger(EntityManager em);


    /**
     * 获取一条数据
     *
     * @param id
     * @return
     */
    T get(ID id);

    /**
     * 删除数据
     *
     * @param ids
     */
    void delete(ID... ids);

    void delete(List<T> list);

    void delete(T t);

    /**
     * 更新数据
     *
     * @param t
     * @return
     */
    T update(T t);

    List<T> update(List<T> list);

    /**
     * 保存数据
     *
     * @param t
     * @return
     */
    T save(T t);

    /**
     * 保存一个集合
     *
     * @param list
     * @return
     */
    List<T> save(List<T> list);

    List<T> findAll();

    List<T> findAll(Sort sort);

    List<T> findList(QueryWrapper query);

    List<T> findList(QueryWrapper query, Sort sort);

    long count(QueryWrapper query);


    List<T> findList(ID[] ids);

    List<T> findList(Collection<ID> list);


    /**
     * 分页查询
     *
     * @param query
     * @param pageable
     * @return
     */
    ResponseEntity<List<T>> findPage(QueryWrapper query, Pageable pageable);

    ResponseEntity<List<T>> findPage(BasicQuery query);


    ResponseEntity<List<T>> findPage(Pageable pageable);

    ResponseEntity<List<T>> findPage(int page, int size);


}
